/*
 * @Descripttion: 
 * @Author: junhuafly
 * @Date: 2020-03-16 14:37:09
 * @LastEditors: junhuafly
 * @Email: junhuafly@163.com
 * @LastEditTime: 2020-03-25 16:28:13
 */
import {commonAPI} from '../api/common'
// import {formatTime} from './util'
class UploadFile{
    constructor(){
        this.logger = wx.getLogManager();
    }
    
    upload(file,type="OTHER",cbk){
        return new Promise((resolve, reject) => {
            wx.showLoading({
                title: '上传中',
            });
            commonAPI.handleUpload({file,type},cbk).then(_=>{
                if(Array.isArray(file)){
                    if(_.length===file.length){
                        resolve(_)
                    }
                    return
                }
                _ = JSON.parse(_)
                if(_.code===200){
                    // this.logger.info(formatTime(new Date(), '上传图片信息，类型为'+type))
                    resolve(_.data)
                }else{
                    reject(_.data||false)
                }
            })
        })
    }
}

const upload = new UploadFile
export {
    upload
}